package com.zhouyu.examplerocketmq.productor;

import com.zhouyu.examplerocketmq.entity.MessageEntity;
import org.apache.rocketmq.common.message.MessageConst;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Description:消息生产者
 */
@Service
public class MessageProducer {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    /**
     * 发送普通消息
     */
    public void sendMsg() {
        rocketMQTemplate.convertAndSend("topic-1", "我是周宇1");
        rocketMQTemplate.syncSend("topic-2", MessageBuilder.withPayload("我是周宇2").setHeader(MessageConst.PROPERTY_KEYS, "123456").build());
        rocketMQTemplate.convertAndSend("topic-4", new MessageEntity("我是周宇4", "1df45d2413145545"));

        rocketMQTemplate.convertAndSend("topic-3:tag-3", "我是周宇3");
    }

}
